package com.coflxl.web.api.common.controller;

import com.coflxl.common.model.ApiResult;
import com.coflxl.web.api.common.model.dto.ApiPage;
import com.coflxl.web.api.common.model.dto.SysCommonSearchPageDTO;
import com.coflxl.web.api.common.model.SysCommonSql;
import com.coflxl.web.api.common.service.CommonService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/common")
public class CommonController {

    @Resource
    private CommonService commonService;

    @PostMapping("/search/{key}")
    public ApiResult search(@PathVariable("key") String key , @RequestBody Map paramMap) throws Exception {
        List p = commonService.search(key,paramMap);
        return ApiResult.ok(p);
    }
    @PostMapping("/searchByOne/{key}")
    public ApiResult searchByOne(@PathVariable("key") String key , @RequestBody Map paramMap) throws Exception {
        Map p = commonService.searchByOne(key,paramMap);
        return ApiResult.ok(p);
    }
    @PostMapping("/searchPage/{key}")
    public ApiResult searchPage(@PathVariable("key") String key , @RequestBody SysCommonSearchPageDTO pageDto) throws Exception {
        ApiPage<Map> page = commonService.searchPage(key,pageDto);
        return ApiResult.ok(page);
    }

    @PostMapping("/add/{key}")
    public ApiResult addKey(@PathVariable("key") String key , @RequestBody Map<String, Object>  paramMap) throws Exception {
        Long p = commonService.addKey(key,paramMap);
        return ApiResult.ok(p);
    }

    @PostMapping("/saveOrUpdate/{table}")
    public ApiResult saveOrUpdate(@PathVariable("table") String table , @RequestBody Map<String, Object>  paramMap) {
        String p = commonService.saveOrUpdate(table,paramMap);
        return ApiResult.ok(p);
    }
}
